package mysqlgo

import (
	"reflect"
	"errors"
)

type field struct {
	names 	[]string
	values 	[]interface{}
}

func (f *field) parseData(data interface{}) {
	getType := reflect.TypeOf(data)
	getValue := reflect.ValueOf(data)
	for i := 0 ; i < getType.NumField(); i++ {
		f.names = append(f.names, getType.Field(i).Name)
		f.values = append(f.values, getValue.Field(i).Interface())
	}
}

func (f *field) parseDatas(datas ...interface{}) ([][]interface{}, error) {
	data := datas[0]
	var values [][]interface{}
	f.parseData(data)
	values = append(values, f.values)
	for i := 1 ; i < len(datas); i++ {
		if !reflect.DeepEqual(data, datas[i]) {
			f.names = f.names[0:0]
			f.values = f.values[0:0]
			return nil, errors.New("[field parseDatas]: The type of datas isn't same")
		}
		f.parseData(datas[i])
		values = append(values, f.values)
	}
	return values, nil
}